<?php
include("conn.php");
  $new = array();
  if (isset($_POST['title'])){
    foreach($_POST['title'] as $key => $value){
      $obj = new stdClass();
      $obj->id = $m_id[$key];
      $obj->instance_id = $instance;
      $obj->title = $value;
      $obj->input_type = $select[$key];
      $obj->width = $width[$key];
      $obj->height = $height[$key];
      $obj->nessary = $nessary[$key];
      $new[] = $obj;
    }
  }
  
  //-------------添加-------------//
  $add = array();
  foreach ($new as &$n) {
    if($n->id == ''){
      $add[] = $n;
    }
  }
  foreach ($add as &$a) {
    DbUtils::add(DbUtils::createPdoInst(), 'pz_tnfp_enq_config', $a);
  }
  
  //-------------删除-------------//
  $del = array(); 
  foreach ($result1 as &$o) {
    $exist = true; 
    foreach ($new as &$n) {
      if ($o->id != $n->id) {
        $exist = false;
      }else{
        $exist = true;
        break;
      }
    }
  if (!$exist) {
        $del[] = $o;
      }
  }
  foreach ($del as &$d) {
    DbUtils::delete(DbUtils::createPdoInst(), 'pz_tnfp_enq_config', $d);
  }
  
    
  //-------------更新-------------//
  $upd = array();
  foreach ($new as &$n) {
    foreach ($result1 as &$o) {
      if($o->id == $n->id){
        $upd[] = $n;
        break;
      }
    }
  }
  foreach ($upd as &$u) {
    DbUtils::update(DbUtils::createPdoInst(), 'pz_tnfp_enq_config', $u);
  }
  
  
  
    $ob = new stdClass();
  if(count($result2)== 0){
    $ob->id = NULL;
    $ob->instance_id = $_POST["instance"];
    $ob->mail_to = $_POST["email"];
    $ob->recepter_name = $_POST["recepter_name"];
    $ob->subject = $_POST["subject"];
    $ob->mail_from = $_POST["mail_from"];
    $ob->sender_name = $_POST["sender_name"];
    $ob->smtp_secure = $_POST["smtp_secure"];
    $ob->host = $_POST["host"];
    $ob->port = $_POST["port"];
    $ob->username = $_POST["username"];
    $ob->password = $_POST["password"];
    $ob->f_bgcolor = $_POST["f_bgcolor"];
    $ob->f_bgcolor_tran = $_POST["f_bgcolor_tran"];
    $ob->f_color = $_POST["f_color"];
    $ob->text_border = $_POST["text_border"];
    $ob->f_font = $_POST["f_font"];
    $ob->f_size = $_POST["f_size"];
    $ob->f_weight = $_POST["f_weight"];
    $ob->cellpadding = $_POST["cellpadding"];
    $ob->b_text = $_POST["b_text"];
    $ob->b_width = $_POST["b_width"];
    $ob->b_height = $_POST["b_height"];
    $ob->b_bgcolor = $_POST["b_bgcolor"];
    $ob->b_color = $_POST["b_color"];
    $ob->b_font = $_POST["b_font"];
    $ob->b_size = $_POST["b_size"];
    $ob->b_weight = $_POST["b_weight"];
    DbUtils::add(DbUtils::createPdoInst(), 'pz_tnfp_enq_email', $ob);
    } else {
    $ob->instance_id = $_POST["instance"];
    $ob->mail_to = $_POST["email"];
    $ob->recepter_name = $_POST["recepter_name"];
    $ob->subject = $_POST["subject"];
    $ob->mail_from = $_POST["mail_from"];
    $ob->sender_name = $_POST["sender_name"];
    $ob->smtp_secure = $_POST["smtp_secure"];
    $ob->host = $_POST["host"];
    $ob->port = $_POST["port"];
    $ob->username = $_POST["username"];
    $ob->password = $_POST["password"];
    $ob->f_bgcolor = $_POST["f_bgcolor"];
    $ob->f_bgcolor_tran = $_POST["f_bgcolor_tran"];
    $ob->f_color = $_POST["f_color"];
    $ob->text_border = $_POST["text_border"];
    $ob->f_font = $_POST["f_font"];
    $ob->f_size = $_POST["f_size"];
    $ob->f_weight = $_POST["f_weight"];
    $ob->cellpadding = $_POST["cellpadding"];
    $ob->b_text = $_POST["b_text"];
    $ob->b_width = $_POST["b_width"];
    $ob->b_height = $_POST["b_height"];
    $ob->b_bgcolor = $_POST["b_bgcolor"];
    $ob->b_color = $_POST["b_color"];
    $ob->b_font = $_POST["b_font"];
    $ob->b_size = $_POST["b_size"];
    $ob->b_weight = $_POST["b_weight"];
    $ob->id = $_POST["e_id"];
    DbUtils::update(DbUtils::createPdoInst(), 'pz_tnfp_enq_email', $ob);
    }
   ?>

